require "import"
require "str"

if activity.getSharedData("password")==nil then
toast("请先登录")
this.finish()
return
end

local cate=1

this.setContentView(loadlayout ({
  FrameLayout,
  --visibility=4,
  backgroundColor=背景色,
  --orientation="vertical",
  --elevation="2%w",
  paddingTop=状态栏高度,

  {
    FrameLayout,
    backgroundDrawable=上下渐变({背景色,深透,淡透}),
    layout_width="fill",
    layout_height="56dp" ,
    --gravity="center",
    padding="16dp",
    --backgroundColor=0xffffffff,
    elevation="2dp",
    paddingTop="8dp",
    paddingBottom="8dp",
    {
      ImageView,
      src="drawable/back.png",
      layout_height="fill",
      layout_width="44dp",
      foreground=波纹(波纹色),
      onClick=function ()
        this.finish()
      end,
      layout_gravity=20,
      padding="9dp",
      colorFilter=图标色,
    },
    {
      TextView,
      layout_width="fill",
      layout_height="fill",
      gravity="center",
      --layout_gravity="center",
      text="经典语录投稿",
      textSize="20sp",
      textColor=文字色,
    },
  },
  {
      ScrollView,
      layout_height="-1";
      elevation=-2,
      layout_width="-1";
      {
        LinearLayout,
        layout_width="fill",
        orientation="vertical",
        paddingLeft="16dp",
      paddingRight="16dp",
      paddingTop="62dp",
      paddingBottom="350dp",
      
      {
      TextView,
      text="句子",
      textSize="14sp",
       textColor=文字色,
       layout_marginLeft="12dp",
      },
       {
       CardView,
       layout_width="fill",
       radius="4dp",
       backgroundColor=0x219e9e9e,
       elevation=0,
       {
       EditText,
       layout_width="fill",
       hint="输入一段话",
       textSize="16sp",
       textColor=文字色,
       id="note",
       padding="12dp",
       backgroundColor=0,
       },
       },
       
        {
      TextView,
      text="句子来源",
      textSize="14sp",
       textColor=文字色,
       layout_marginLeft="12dp",
      },
       {
       CardView,
       layout_width="fill",
       radius="4dp",
       backgroundColor=0x219e9e9e,
       elevation=0,
       {
       EditText,
       layout_width="fill",
       hint="",
       textSize="16sp",
       textColor=文字色,
       id="source",
       padding="12dp",
       backgroundColor=0,
       },
       },
       
       {
      TextView,
      text="作者",
      textSize="14sp",
       textColor=文字色,
       layout_marginLeft="12dp",
      },
       {
       CardView,
       layout_width="fill",
       radius="4dp",
       backgroundColor=0x219e9e9e,
       elevation=0,
       {
       EditText,
       layout_width="fill",
       hint="由谁创作",
       textSize="16sp",
       textColor=文字色,
       id="author",
       padding="12dp",
       backgroundColor=0,
       },
       },
       
       {
      TextView,
      text="邮箱",
      textSize="14sp",
       textColor=文字色,
       layout_marginLeft="12dp",
      },
       {
       CardView,
       layout_width="fill",
       radius="4dp",
       backgroundColor=0x219e9e9e,
       elevation=0,
       {
       EditText,
       layout_width="fill",
       hint="投稿通过后，将会通过此邮箱通知",
       textSize="16sp",
       textColor=文字色,
       id="email",
       text=activity.getSharedData("classic_sayings_post_email",""),
       padding="12dp",
       backgroundColor=0,
       },
       },
       
       {
            LinearLayout,
            layout_marginBottom="16dp",
            gravity=17,
            padding="12dp",
            layout_width=-1,
            onClick=function(v)
           
            v=v.getChildAt(1)
            local pop=PopupMenu(this,v)
        local menu=pop.Menu
        local function setText(a)
          v.setText(tostring(a))
        end
        for k,v in ipairs{
        "动画",
        "漫画",
        "游戏",
        "网络",
        "文学",
        "原创",
        "其他",
        "影视",
        "诗词",
        "云音乐",
        "哲学",
        "抖机灵"
        } do
        menu.add(v).onMenuItemClick=function(i)
          setText(i)
          cate=k
         end
        end
        pop.show()
  
            end,
            foreground=波纹(波纹色),
            {
            TextView,
            text="分类",
            textSize="16sp",
            textColor=文字色,
            layout_marginRight="12dp",
            layout_weight=1,
            },
            {
            TextView,
            text="动画",
            id="cateSpin",
            textSize="16sp",
            textColor=文字色,
            },
            },
            
     };
   },
   {
        LinearLayout,
        layout_gravity="bottom",
        layout_width="fill",
        backgroundDrawable=上下渐变({1,背景色,背景色}),
   {
   TextView,
   text="投稿",
   layout_height="56dp" ,
   foreground=波纹(波纹色),
   onClick=function()
   
   toast("正在投稿")
   
    Http.post(
    --"http://yuju.aixinbiji.com:80/model/submit.php",
    getApiUrl("juyu","model/submit.php",80),
    "content="..note.text..
    "&type="..utf8.sub("abcdefghijkl",cate,cate)..
    "&from_where="..source.text..
    "&from_who="..author.text..
    "&email="..email.text,function(c,n)
 --   this.setDebug(true)
    print(c,getApiUrl("juyu","model/submit.php",80),n)
      if c==200 then
      note.text=""
      source.text=""
      author.text=""
toast("投稿成功")
        else
toast("投稿失败，检查网络或稍后再试")
      end
    end)
   
   end,
   textColor=文字色,
   layout_width="fill",
   layout_margin="16dp",
   gravity="center",
   padding="12dp",
   backgroundDrawable=圆角(nil,0x219e9e9e,{4,4,4,4,4,4,4,4}),
   },
   },
}))

function onPause()
activity.setSharedData("classic_sayings_post_email",email.text)
end

